package com.w.picture.common;

import java.util.Random;

/**
 * 唯一用户名生成器
 * @author wzp
 * @since 2024/12/15
 */


public class UniqueUsernameGenerator {

    private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    private static final int RANDOM_PART_LENGTH = 6; // 随机部分的长度可以根据需要调整
    private static final Random random = new Random();

    public static String generateUniqueUsername() {
        // 时间戳部分保证大部分情况下生成的用户名是唯一的
        long timestamp = System.currentTimeMillis();
        // 随机字符部分提供额外的随机性
        StringBuilder randomPart = new StringBuilder(RANDOM_PART_LENGTH);
        for (int i = 0; i < RANDOM_PART_LENGTH; i++) {
            int index = random.nextInt(CHARACTERS.length());
            randomPart.append(CHARACTERS.charAt(index));
        }
        return "User_" + timestamp + "_" + randomPart.toString();
    }

    public static void main(String[] args) {
        System.out.println(generateUniqueUsername());
    }
}